package com.nuo.common.core.result;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author LGC
 * @date 2022/1/26 11:36
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public enum ResultCode implements IResultCode, Serializable {
    /**
     *
     */
    SUCCESS("200", "成功"),
    ERROR("-200", "系统执行出错"),

    USER_LOGIN_ERROR("1001", "用户登录异常"),
    USER_NOT_EXIST("1002", "用户不存在"),
    USER_ACCOUNT_LOCKED("1002", "用户账户被冻结"),
    USER_ACCOUNT_INVALID("1003", "用户账户已作废"),

    USERNAME_OR_PASSWORD_ERROR("1101", "用户名或密码错误"),
    PASSWORD_ENTER_EXCEED_LIMIT("1102", "用户输入密码次数超限"),
    CLIENT_AUTH_FAILED("1103", "客户端认证失败"),
    TOKEN_INVALID_OR_EXPIRED("1104", "token无效或已过期"),
    TOKEN_FORBIDDEN("1105", "token已被禁止访问"),
    PARAM_ERROR("1106", "用户请求参数错误"),
    RESOURCE_NOT_FOUND("1107", "请求资源不存在"),
    PARAM_IS_NULL("1108", "请求必填参数为空"),

    ACCESS_PERMISSION_ERROR("1201", "访问权限异常"),
    ACCESS_UNAUTHORIZED("1202", "访问未授权"),

    FORBIDDEN_OPERATION("1301", "演示环境禁止修改、删除重要数据，请本地部署后测试"),

    FLOW_LIMITING("B0210", "系统限流"),
    DEGRADATION("B0220", "系统功能降级"),
    ;

    private String code;

    private String msg;

    @Override
    public String toString() {
        return "{" +
                "\"code\":\"" + code + '\"' +
                ", \"msg\":\"" + msg + '\"' +
                '}';
    }

    public static ResultCode getValue(String code) {
        for (ResultCode resultCode : values()) {
            if (resultCode.getCode().equals(code)) {
                return resultCode;
            }
        }
        return ERROR;
    }
}
